package cn.itcast.mq.config;


import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.amqp.support.converter.MessageConverter;
@Configuration
public class FanoutExchangeConfig {


//    创建队列1  fanout.queue1
    @Bean
    public Queue queue1(){
        return new Queue("fanout.queue1");
    }
//    创建交换机 fanoutExchange
    @Bean
    public FanoutExchange fanoutExchange(){
        return new FanoutExchange("fanoutExchange");
    }
//   队列1绑定交换机
    @Bean
    public Binding bindingExchange1(){
        return BindingBuilder.bind(queue1()).to(fanoutExchange());
    }
    //    创建队列1  fanout.queue2
    @Bean
    public Queue queue2(){
        return new Queue("fanout.queue2");
    }
    //   队列2绑定交换机
    @Bean
    public Binding bindingExchange2(){
        return BindingBuilder.bind(queue2()).to(fanoutExchange());
    }


    @Bean
    public Queue objQueue(){
        return new Queue("obj.queue");
    }

    @Bean
    public MessageConverter messageConverter() {
        return new Jackson2JsonMessageConverter();
    }
}
